package com.work.controller;

import com.work.bean.HwStuAttach;
import com.work.dao.HwStuAttachDao;
import com.work.dao.impl.HwStuAttachDaoImpl;
import com.work.utils.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class HwStuAttachServlet extends BaseServlet{
    HwStuAttachDao hwStuAttachDao = new HwStuAttachDaoImpl();
    protected void queryHwStuAttach(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        List<HwStuAttach> hwStuAttachs = hwStuAttachDao.queryHwStuAttach();
        req.setAttribute("hwStuAttach",hwStuAttachs);
        req.getRequestDispatcher("/page/admin/admin_hw.jsp").forward(req,resp);
    }
    protected void queryHwStuAttachById(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        int id = WebUtils.parseInt(req.getParameter("id"),0);
        HwStuAttach hwStuAttach = hwStuAttachDao.queryHwStuAttachById(id);
        req.setAttribute("hwStuAttach",hwStuAttach);
        req.getRequestDispatcher("/page/admin/admin_hw.jsp").forward(req,resp);
    }
    protected void saveHwStuAttach(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {

    }
    protected void updateHwStuAttach(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        int id = WebUtils.parseInt(req.getParameter("id"),0);
        HwStuAttach hwStuAttach = hwStuAttachDao.queryHwStuAttachById(id);
        req.setAttribute("hwStuAttach",hwStuAttach);
        req.getRequestDispatcher("/page/admin/admin_hw.jsp").forward(req,resp);
    }
    protected void deleteHwStuAttach(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        int id = WebUtils.parseInt(req.getParameter("id"),0);
        hwStuAttachDao.deleteHwStuAttach(id);
        resp.sendRedirect(req.getContextPath() + "/HwStuAttachServlet?action=queryHwStuAttach");
    }
}
